from flask import Flask, render_template, request, flash, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine, Column, Integer, Text, DateTime, SMALLINT, Float, Boolean
app = Flask(__name__,instance_relative_config=True,template_folder='templates')
app.config['SECRET_KEY'] = "random string"
HOSTNAME = "127.0.0.1"
PORT = 3306
USERNAME = "root"
PASSWORD = "root"
DATABASE = "flask_games"
# 拼接式创建
app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOSTNAME}:{PORT}/{DATABASE}?charset=utf8mb4"
# 每次执行会连接到 flask库
db = SQLAlchemy(app)

class dashboard_agency(db.Model):
    __tablename__  = "dashboard_agency"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=True)

    earnings = db.Column(db.String(32),nullable=True, comment='收益')
    orderNumber = db.Column(db.String(32),nullable=True, comment='订单数量')
    JSONData = image = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.Text,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy

class set_meal(db.Model):
    __tablename__  = "set_meal"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=False)

    set_meal_money = db.Column(db.String(64),nullable=True, comment='套餐价格')
    set_meal_shop = db.Column(db.Text,nullable=True, comment='套餐包含商品')
    title = db.Column(db.String(64),nullable=True, comment='套餐标题')
    details = db.Column(db.String(64),nullable=True, comment='套餐详情')
    set_meal_type = db.Column(db.String(64),nullable=True, comment='套餐分类')
    set_meal_type_id = db.Column(db.String(64), nullable=True, comment='套餐分类id')
    sort = db.Column(db.Integer,nullable=True, comment='排序')
    image = db.Column(db.Text,comment='套餐图片', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.DateTime,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy

class dashboard(db.Model):
    __tablename__  = "dashboard"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=True)
    total_number = db.Column(db.Integer,nullable=True, comment='总交易数')
    total_cash = db.Column(db.Integer,nullable=True, comment='总成交额')
    total_visit = db.Column(db.Integer,nullable=True, comment='访问人数')

    JSONData = image = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.Text,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy

class operation_log(db.Model):
    __tablename__  = "operation_log"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=True)
    visit_ip = db.Column(db.String(32),nullable=True, comment='访问ip')
    visit_path = db.Column(db.Text,nullable=True, comment='访问路由')
    visit_param = db.Column(db.Text,nullable=True, comment='访问参数')
    visit_type = db.Column(db.Text,nullable=True, comment='访问类型') # py,wx,pc
    JSONData = image = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.Text,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy

class error_log(db.Model):
    __tablename__  = "error_log"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=True)
    error_content = db.Column(db.Text,nullable=True, comment='错误内容')
    error_path = db.Column(db.Text,nullable=True, comment='错误路由')
    visit_ip = db.Column(db.Text,nullable=True, comment='访问ip') # py,wx,pc
    JSONData = image = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.Text,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy
    
class white_list(db.Model):
    __tablename__  = "white_list"
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    user_id = db.Column(db.String(32),nullable=True)
    white_ip = db.Column(db.String(32),nullable=True, comment='白名单网络ip')
    JSONData = image = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime,nullable=True, comment='创建时间')
    template_id = db.Column(db.DateTime,nullable=True, comment='模版id') # 模版id
    USER_SERVICE_TOKEN = db.Column(db.Text,nullable=True, comment='服务标识') # 小程序通过服务标识来确定小程序数据
    status = db.Column(db.String(32),nullable=True,comment='状态') # normal  删除destroy  



# 充值记录
class rechargeRecord(db.Model):
    __tablename__ = "rechargeRecord"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # False不能为空   True可以为空
    recharge_id = db.Column(db.String(255),comment='充值id', )  # False不能为空   True可以为空
    merchant_id = db.Column(db.String(255), comment='商家id', nullable=True)
    merchant_number = db.Column(db.String(255), comment='商户号', nullable=True)
    phone = db.Column(db.String(255), comment='用户手机号码', nullable=True)
    payment_number = db.Column(db.String(255), comment='支付单号', nullable=True)
    recharge_balance = db.Column(db.Integer, comment='充值余额', nullable=True)
    payment_cash = db.Column(db.Integer, comment='支付金额', nullable=True)
    payment_type = db.Column(db.String(255), comment='支付方式', nullable=True)
    channel = db.Column(db.String(255), comment='充值渠道', nullable=True)
    explain = db.Column(db.Text, comment='说明', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    status = db.Column(db.String(32), nullable=True, comment='状态')

# 充值展示
class rechargeShow(db.Model):
    __tablename__ = "rechargeShow"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # False不能为空   True可以为空
    merchant_id = db.Column(db.String(255), comment='商家id', nullable=True)
    plugin_id = db.Column(db.String(255), comment='商家id', nullable=True)
    currency_balance = db.Column(db.Integer, comment='充值金额', nullable=True)
    payment_cash = db.Column(db.Integer, comment='支付金额', nullable=True)
    give_cash = db.Column(db.Integer, comment='赠送金额', nullable=True)
    recharge_type = db.Column(db.String(255), comment='充值类型', nullable=True)
    recharge_type_id = db.Column(db.String(255), comment='充值类型id', nullable=True)
    explain = db.Column(db.Text, comment='说明', nullable=True)
    sort = db.Column(db.Integer, comment='排序', nullable=True)
    channel = db.Column(db.Text, comment='充值渠道', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    status = db.Column(db.String(32), nullable=True, comment='状态')

# 文章
class article(db.Model):
    __tablename__ = "article"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # False不能为空   True可以为空
    user_id = db.Column(db.String(255), comment='商家id', nullable=True)
    wechat_id = db.Column(db.String(255), comment='微信用户', nullable=True)
    article_title = db.Column(db.Text, comment='文章标题', nullable=True)
    article_cover = db.Column(db.Text, comment='文章封面', nullable=True)
    article_image = db.Column(db.Text, comment='文章图片', nullable=True)
    article_type = db.Column(db.String(255), comment='文章类型', nullable=True)
    article_type_id = db.Column(db.String(255), comment='文章类型id', nullable=True)
    Text = db.Column(db.Text, comment='富文本', nullable=True)
    quote = db.Column(db.String(255), comment='引用', nullable=True)
    explain = db.Column(db.Text, comment='说明', nullable=True)
    channel = db.Column(db.Text, comment='充值渠道', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    sort = db.Column(db.Integer, comment='排序', nullable=True)
    recommend = db.Column(db.Integer, comment='推荐位', nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    status = db.Column(db.String(32), nullable=True, comment='状态')

# 风景
class scenery(db.Model):
    __tablename__ = "scenery"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # False不能为空   True可以为空
    user_id = db.Column(db.String(255), comment='商家id', nullable=True)
    wechat_id = db.Column(db.String(255), comment='微信用户', nullable=True)
    scenery_title = db.Column(db.Text, comment='风景标题', nullable=True)
    scenery_type = db.Column(db.Text, comment='风景类型', nullable=True)
    scenery_image = db.Column(db.Text, comment='风景图片', nullable=True)
    scenery_cover = db.Column(db.Text, comment='风景封面', nullable=True)
    sort = db.Column(db.Integer, comment='排序', nullable=True)
    activate = db.Column(db.Integer, comment='激活状态', nullable=True)
    longitude = db.Column(db.Text, comment='longitude', nullable=True)
    latitude = db.Column(db.Text, comment='latitude', nullable=True)
    address = db.Column(db.Text, comment='风景地址', nullable=True)
    Text = db.Column(db.Text, comment='富文本', nullable=True)
    explain = db.Column(db.Text, comment='说明', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    recommend = db.Column(db.Integer, comment='推荐位', nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    status = db.Column(db.String(32), nullable=True, comment='状态')

# 其它类型
class other_type(db.Model):
    __tablename__ = "other_type"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # False不能为空   True可以为空
    user_id = db.Column(db.String(255), comment='商家id', nullable=True)
    type_title = db.Column(db.Text, comment='类型名称', nullable=True)
    type_image = db.Column(db.Text, comment='图片', nullable=True)
    type_cover = db.Column(db.Text, comment='图片封面', nullable=True)
    sort = db.Column(db.Integer, comment='排序', nullable=True)
    Text = db.Column(db.Text, comment='富文本', nullable=True)
    explain = db.Column(db.Text, comment='说明', nullable=True)
    JSONData = db.Column(db.Text,comment='json数据', nullable=True)
    recommend = db.Column(db.Integer, comment='推荐位', nullable=True)
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    status = db.Column(db.String(32), nullable=True, comment='状态')


with app.app_context():
    db.create_all()